package org.nstack.header.vm;

import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.nstack.header.rest.RestRequest;
import org.springframework.http.HttpMethod;
import org.nstack.header.identity.Action;
import org.nstack.header.notification.ApiNotification;


@Action(category = VmInstanceConstant.ACTION_CATEGORY)
@RestRequest(
        path = "/vm-instances/{uuid}/actions",
        method = HttpMethod.PUT,
        responseClass = APIStopVmInstanceEvent.class,
        isAction = true
)
public class APIStopVmInstanceMsg extends APIMessage implements VmInstanceMessage {

    @APIParam(resourceType = VmInstanceVO.class, checkAccount = true, operationTarget = true)
    private String uuid;
    @APIParam(required = false, validValues = {"grace", "cold"})
    private String type = "grace";

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }


    @Override
    public String getVmInstanceUuid() {
        return getUuid();
    }
 
    public static APIStopVmInstanceMsg __example__() {
        APIStopVmInstanceMsg msg = new APIStopVmInstanceMsg();
        msg.setUuid(uuid());
        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                ntfy("Stopped").resource(uuid, VmInstanceVO.class.getSimpleName())
                        .messageAndEvent(that, evt).done();
            }
        };
    }

}
